<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
$time_start = getMicro_Time();
include_once("Sub_ListResult.php");
$time_end = getMicro_Time();

$fp = @file($strTemplatePath."Sub_List.html");
$fp = implode("", $fp);
$fp = setHTMLCharset($fp);

	$fp = str_replace("{Show_SubID}", $_data["SubID"], $fp);
	$fp = str_replace("{Show_SubAccount}", $arrAccount[$data["SubID_n"]], $fp);
	$fp = str_replace("{Show_MainID}", $_data["MainID"], $fp);
	$fp = str_replace("{Show_LottoID}", $_data["LottoID"], $fp);
	$fp = str_replace("{Show_Bet_Type}", $_data["Bet_Type"], $fp);
	$fp = str_replace("{Show_PayupDate_0}", $data["PayupDate_x"][0], $fp);
	$fp = str_replace("{Show_PayupDate_1}", $data["PayupDate_x"][1], $fp);
	$fp = str_replace("{LottoContent}",  (empty($_data["LottoID"]))?"All":$_arrLotto[$_data["LottoID"]]["Lotto_".$_intLang], $fp);
	$fp = str_replace("{BetTypeContent}", (empty($_data["Bet_Type"]))?"All":$_arrBet_Type[$_arrLotto[$_data["LottoID"]]["LType"]][$_data["Bet_Type"]], $fp);
	$fp = str_replace("{Show_Types}", ((empty($_data["Types"]))?"Agent":$_data["Types"]), $fp);

	if(!empty($_data["MainID"])){
		$fp = preg_replace("/<!--@ ShowBar Start @\/\/-->.+<!--@ ShowBar End @\/\/-->/s", "", $fp);
	}

	while(list($k, $v) = each($_strAccount_Agent)){
		$fp = str_replace("{".$k."}", $v, $fp);
	}

	preg_match("/<!--@ BetContent Start @\/\/-->(.+)<!--@ BetContent End @\/\/-->/s", $fp, $d);
	preg_match("/<!--@ SuppleBetContent Start @\/\/-->(.+)<!--@ SuppleBetContent End @\/\/-->/s", $fp, $sd);
	$sumTotals = 0;
	$sumMemStake = 0;
	$sumMemResult = 0;
	$sumMemRBM = 0;
	$sumAgentRateWin = 0;
	$sumAgentComm = 0;
	$sumAgentWin = 0;
	$sumAgentResult = 0;
	$sumRealMemCommission = 0;

	$tolTotals = 0;
	$tolMemStake = 0;
	$tolMemResult = 0;
	$tolMemRBM = 0;
	$tolAgentRateWin = 0;
	$tolAgentComm = 0;
	$tolAgentWin = 0;
	$tolAgentResult = 0;
	$tolRealMemResult = 0;
	//一般帳
	if(is_array($arrRows[0])){
		while(list($k, $Rows) = each($arrRows[0])){
			if($intReportType == 0){
				$tmp = str_replace("{Show_Member}", $arrAccount[$Rows -> MemID], $d[1]);
				$tmp = str_replace("{MemID}", $Rows -> MemID, $tmp);
			}else{
				$tmp = str_replace("{Show_Member}", $_arrBet_Type[$_arrLotto[$Rows -> LottoID]["LType"]][$Rows -> Bet_Type], $d[1]);
				$tmp = str_replace("Bet('{MemID}')", "ReportType('".$Rows -> LottoID."','".$Rows -> Bet_Type."', 0)", $tmp);
			}
			$tmp = str_replace("{Totals}", number_format($Rows -> totals), $tmp);
			$tmp = str_replace("{MemStake}", sprintf("%.1f", $Rows -> MemStake), $tmp);
			$flMemResult = round($Rows -> SubIncome, 1);
			$tmp = str_replace("{SMemResult}", sprintf("%.1f", $Rows -> SubIncome), $tmp);
			$tmp = str_replace("{SER}", sprintf("%.3f", $Rows -> MemExchangeRate), $tmp);
			$flMemRBM = round($Rows -> SubIncome*$Rows -> MemExchangeRate, 1);
			$tmp = str_replace("{SMemRBM}", sprintf("%.1f", $flMemRBM), $tmp);
			$tmp = str_replace("{SA%}", sprintf("%.2f", 1 - $Rows -> SubRate), $tmp);
			$tmp = str_replace("{SAgentComm}", sprintf("%.2f", $Rows -> SubComm), $tmp);
			$flAgentWin = round($flMemRBM - $Rows -> SubRateResult, 1);
			//$flAgentWin = round($Rows -> SubResult - $Rows -> SubRateResult, 1);
			$tmp = str_replace("{SAgentRateWin}", sprintf("%.1f", $flAgentWin - $Rows -> SubComm), $tmp);
			$tmp = str_replace("{SAgentWin}", sprintf("%.1f", $flAgentWin), $tmp);
			$tmp = str_replace("{SG%}", sprintf("%.2f", $Rows -> SubRate), $tmp);
			$flAgentResult = round($Rows -> SubRateResult, 1);
			$tmp = str_replace("{SAgentResult}", sprintf("%.1f", $flAgentResult), $tmp);
			$flRealMemCommission = round($Rows -> RealMemCommission, 1);
			$tmp = str_replace("{SMemCo}", sprintf("%.1f", $flRealMemCommission), $tmp);
			$strCon .= $tmp;

			$sumTotals += $Rows -> totals;
			$sumMemStake += $Rows -> MemStake;
			$sumMemResult += $flMemResult;
			$sumMemRBM += $flMemRBM;
			$sumAgentRateWin += $flAgentWin - $Rows -> SubComm;
			$sumAgentComm += $Rows -> SubComm;
			$sumAgentWin += $flAgentWin;
			$sumAgentResult += $flAgentResult;
			$sumRealMemCommission += $flRealMemCommission;

			$tolTotals += $Rows -> totals;
			$tolMemStake += $Rows -> MemStake;
			$tolMemResult += $flMemResult;
			$tolMemRBM += $flMemRBM;
			$tolAgentRateWin += $flAgentWin - $Rows -> SubComm;
			$tolAgentComm += $Rows -> SubComm;
			$tolAgentWin += $flAgentWin;
			$tolAgentResult += $flAgentResult;
			$tolRealMemResult += round($Rows -> RealMemResult, 1);
			//print $tolRealMemResult;
		}
		@mysql_free_result($RS);
	}
	$fp = preg_replace("/<!--@ BetContent Start @\/\/-->.+<!--@ BetContent End @\/\/-->/s", $strCon, $fp);
	$fp = str_replace("{SumTotals}", number_format($sumTotals), $fp);
	$fp = str_replace("{SumMemStake}", sprintf("%.1f", $sumMemStake), $fp);
	$fp = str_replace("{SumMemResult}", sprintf("%.1f", $sumMemResult), $fp);
	$fp = str_replace("{SumMemRBM}", sprintf("%.1f", $sumMemRBM), $fp);
	$fp = str_replace("{SumAgentRateWin}", sprintf("%.1f", $sumAgentRateWin), $fp);
	$fp = str_replace("{SumAgentComm}", sprintf("%.2f", $sumAgentComm), $fp);
	$fp = str_replace("{SumAgentWin}", sprintf("%.1f", $sumAgentWin), $fp);
	$fp = str_replace("{SumAgentResult}", sprintf("%.1f", $sumAgentResult), $fp);
	$fp = str_replace("{SumMemCo}", sprintf("%.1f", $sumRealMemCommission), $fp);

	$sumTotals = 0;
	$sumMemStake = 0;
	$sumMemResult = 0;
	$sumMemRBM = 0;
	$sumAgentRateWin = 0;
	$sumAgentComm = 0;
	$sumAgentWin = 0;
	$sumAgentResult = 0;
	$sumRealMemCommission = 0;
	$sumAgentSuppleWin = 0;
	$strCon = "";
	//補貨帳
	if(is_array($arrRows[1])){
		while(list($k, $Rows) = each($arrRows[1])){
			if($intReportType == 0){
				$tmp = str_replace("{Show_Member}", $arrAccount[$Rows -> MemID], $sd[1]);
				$tmp = str_replace("Bet('{MemID}')", "ReportType('".$Rows -> LottoID."','".$Rows -> Bet_Type."', 2)", $tmp);
			}else{
				$tmp = str_replace("{Show_Member}", $_arrBet_Type[$_arrLotto[$Rows -> LottoID]["LType"]][$Rows -> Bet_Type], $sd[1]);
				$tmp = str_replace("Bet('{MemID}')", "ReportType('".$Rows -> LottoID."','".$Rows -> Bet_Type."', 2)", $tmp);
			}
			$tmp = str_replace("{Totals}", number_format($Rows -> totals), $tmp);
			$tmp = str_replace("{MemStake}", sprintf("%.1f", $Rows -> MemStake), $tmp);
			$flMemResult = round($Rows -> SubIncome, 1);
			$tmp = str_replace("{SMemResult}", sprintf("%.1f", $Rows -> SubIncome), $tmp);
			$tmp = str_replace("{SER}", sprintf("%.3f", $Rows -> MemExchangeRate), $tmp);
			$flMemRBM = round($Rows -> SubIncome*$Rows -> MemExchangeRate, 1);
			$tmp = str_replace("{SMemRBM}", sprintf("%.1f", $flMemRBM), $tmp);
			$tmp = str_replace("{SA%}", sprintf("%.2f", 1 - $Rows -> SubRate), $tmp);
			$tmp = str_replace("{SAgentComm}", sprintf("%.2f", $Rows -> SubComm), $tmp);
			$flAgentWin = round(0 - $Rows -> SubRateResult, 1);
			$tmp = str_replace("{SAgentRateWin}", sprintf("%.1f", 0), $tmp);
			$tmp = str_replace("{SAgentWin}", sprintf("%.1f", $flAgentWin), $tmp);
			$tmp = str_replace("{SG%}", sprintf("%.2f", $Rows -> SubRate), $tmp);
			$flAgentResult = round($Rows -> SubRateResult, 1);
			$tmp = str_replace("{SAgentResult}", sprintf("%.1f", $flAgentResult), $tmp);
			$flRealMemCommission = round($Rows -> RealMemCommission, 1);
			$tmp = str_replace("{SMemCo}", sprintf("%.1f", $flRealMemCommission), $tmp);
			$strCon .= $tmp;

			$sumTotals += $Rows -> totals;
			$sumMemStake += $Rows -> MemStake;
			$sumMemResult += $flMemResult;
			$sumMemRBM += $flMemRBM;
			$sumAgentComm += $Rows -> SubComm;
			$sumAgentWin += $flAgentWin;
			$sumAgentResult += $flAgentResult;
			$sumRealMemCommission += $flRealMemCommission;

			$tolTotals += $Rows -> totals;
			$tolMemStake += $Rows -> MemStake;
			$tolMemResult += $flMemResult;
			$tolMemRBM += $flMemRBM;
			$tolAgentComm += $Rows -> SubComm;
			$tolAgentWin -= $flAgentWin;
			$tolAgentResult += $flAgentResult;
			$tolRealMemResult += round($Rows -> RealMemResult, 1);
		}
		@mysql_free_result($RS);
	}
	$fp = preg_replace("/<!--@ SuppleBetContent Start @\/\/-->.+<!--@ SuppleBetContent End @\/\/-->/s", $strCon, $fp);
	$fp = str_replace("{SuppleSumTotals}", number_format($sumTotals), $fp);
	$fp = str_replace("{SuppleSumMemStake}", sprintf("%.1f", $sumMemStake), $fp);
	$fp = str_replace("{SuppleSumMemResult}", sprintf("%.1f", $sumMemResult), $fp);
	$fp = str_replace("{SuppleSumMemRBM}", sprintf("%.1f", $sumMemRBM), $fp);
	$fp = str_replace("{SuppleSumAgentRateWin}", sprintf("%.1f", 0), $fp);
	$fp = str_replace("{SuppleSumAgentComm}", sprintf("%.1f", $sumAgentComm), $fp);
	$fp = str_replace("{SuppleSumAgentWin}", sprintf("%.1f", $sumAgentWin), $fp);
	$fp = str_replace("{SuppleSumAgentResult}", sprintf("%.1f", $sumAgentResult), $fp);
	$fp = str_replace("{SuppleSumMemCo}", sprintf("%.1f", $sumRealMemCommission), $fp);

	//總帳
	$fp = str_replace("{ShowAgent}", $arrAccount[$data["SubID_n"]], $fp);
	$fp = str_replace("{tolTotals}", number_format($tolTotals), $fp);
	$fp = str_replace("{tolMemStake}", sprintf("%.1f", $tolMemStake), $fp);
	$fp = str_replace("{tolWinLose}", sprintf("%.1f", $tolRealMemResult), $fp);
	$fp = str_replace("{tolComm}", sprintf("%.1f", $tolAgentResult - $tolRealMemResult), $fp);
	$fp = str_replace("{tolResult}", sprintf("%.1f", $tolAgentResult), $fp);
$fp .= "\n<a style='font-size: 10px; color: #DDDDDD'>".(string)($time_end - $time_start)."</a>";
//輸出
WebOutputHTML($fp, 1);
?>